package org.oschina.api.friendlink.dao;

import java.util.List;
import org.oschina.api.BaseDAO;
import org.oschina.api.friendlink.model.Friendlink;
import org.oschina.api.friendlink.vo.FriendlinkVo;
import org.springframework.stereotype.Repository;

@Repository
public class FriendlinkDAO extends BaseDAO {

	private final String findVo[]={"id","name","text","url","`explain`","color","font","`index`","create_time"};
	
	/**
	 * 返回
	 * @return
	 */
	public List<FriendlinkVo> findVo()
	{
		return getQueryHelper().query_cache(findVo, null, new String[]{"ORDER BY `index`"}, null, FriendlinkVo.class, -1, -1);
	}
	
	/**
	 * 创建
	 * @param friendLink
	 * @return
	 */
	public Friendlink create(Friendlink friendLink)
	{
		getQueryHelper().insert_cache(new String[]{"id","name","text","url","`explain`","color","font","`index`","create_time"}, 
				new Object[]{friendLink.getId(),friendLink.getName(),friendLink.getText(),friendLink.getUrl(),friendLink.getExplain(),friendLink.getColor(),
				friendLink.getFont(),friendLink.getIndex(),friendLink.getCreate_time()}, FriendlinkVo.class);
		return friendLink;
	}
	
	/**
	 * 更新
	 * @param friendLink
	 * @return
	 */
	public int update(Friendlink friendLink)
	{
		return (int) getQueryHelper().update_cache(new String[]{"name=?","text=?","url=?","`explain`=?","color=?","font=?","`index`=?"}, 
				new String[]{"id=?"},
				new Object[]{friendLink.getName(),friendLink.getText(),friendLink.getUrl(),friendLink.getExplain(),
					friendLink.getColor(),friendLink.getFont(),friendLink.getIndex(),friendLink.getId()}, FriendlinkVo.class);
	}
	
	/**
	 * 删除
	 * @param id
	 * @return
	 */
	public int remove(int id)
	{
		return (int) getQueryHelper().delete_cache(new String[]{"id=?"}, new Object[]{id}, FriendlinkVo.class);
	}
}